package cn.flying.cloud.oa.leave.service.impl;

import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.oa.leave.entity.OaLeaveApply;
import cn.flying.cloud.oa.leave.mapper.OaLeaveApplyMapper;
import cn.flying.cloud.oa.leave.service.OaLeaveApplyService;

/**
 * 请假流程申请表 服务实现类
 *
 * @author admin
 * @since 2024-12-26 20:48:41
 */
@Service
public class OaLeaveApplyServiceImpl extends ServiceImpl<OaLeaveApplyMapper, OaLeaveApply> implements OaLeaveApplyService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 查询总数
     *
     * @param oaLeaveApply
     * @return
     */
    @Override
    public long countObj(OaLeaveApply oaLeaveApply) {
        return this.count(getLambdaQueryWrapper(oaLeaveApply));
    }

    /**
     * 分页查询请假流程申请表数据
     *
     * @param request
     * @return
     */
    @Override
    public PageResponse<OaLeaveApply> getPageList(PageRequest<OaLeaveApply> request) {
        OaLeaveApply param = request.getParam();
        LambdaQueryWrapper<OaLeaveApply> wrapper = getLambdaQueryWrapper(param);
        // wrapper TODO
        Page<OaLeaveApply> page = this.page(new Page<>(request.getPageNum(), request.getPageSize()), wrapper);
        return new PageResponse<>(page.getTotal(), (int) page.getCurrent(), page.getRecords());
    }

    /**
     * 构建查询对象
     *
     * @param param
     * @return
     */
    private LambdaQueryWrapper<OaLeaveApply> getLambdaQueryWrapper(OaLeaveApply param) {
        LambdaQueryWrapper<OaLeaveApply> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return wrapper;
    }

    /**
     * 列表查询请假流程申请表数据
     *
     * @param oaLeaveApply
     * @return
     */
    @Override
    public List<OaLeaveApply> getList(OaLeaveApply oaLeaveApply) {
        LambdaQueryWrapper<OaLeaveApply> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        List<OaLeaveApply> list = this.list(wrapper);
        return list;
    }

    /**
     * 查询请假流程申请表详情数据
     *
     * @param oaLeaveApply
     * @return
     */
    @Override
    public OaLeaveApply getOneObj(OaLeaveApply oaLeaveApply) {
        LambdaQueryWrapper<OaLeaveApply> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return this.getOne(wrapper);
    }

    /**
     * 根据Id查询请假流程申请表详情数据
     *
     * @param id
     * @return
     */
    @Override
    public OaLeaveApply getObjById(Serializable id) {
        return this.getById(id);
    }

    /**
     * 新增请假流程申请表数据
     *
     * @param oaLeaveApply
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean createObj(OaLeaveApply oaLeaveApply) {
        return this.save(oaLeaveApply);
    }

    /**
     * 更新请假流程申请表数据
     *
     * @param oaLeaveApply
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateObj(OaLeaveApply oaLeaveApply) {
        return this.saveOrUpdate(oaLeaveApply);
    }

    /**
     * 删除请假流程申请表数据
     *
     * @param oaLeaveApply
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteObj(OaLeaveApply oaLeaveApply) {
        LambdaQueryWrapper<OaLeaveApply> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return this.remove(wrapper);
    }

    /**
     * 根据Id删除请假流程申请表数据
     *
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteById(Serializable id) {
        return this.removeById(id);
    }
}
